package tests;

import static org.junit.Assert.assertTrue;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import cruncher.FixToOneFixingStrategy;
import cruncher.FixingStrategy;
import cruncher.IFixingStrategy;
import cruncher.Solution;
import cruncher.Utils;
import cruncher.Variable;

public class FixStrategyTester {

	IFixingStrategy fix = null;
	Solution sol = new Solution(0);
	
	public FixStrategyTester()
	{
		int num = 100;
		for (int x=0; x < num; x++)
		{
			sol.add(new Variable("A"+x,Utils.TYPE_INTEGER,1.0*x));
		}
	}
	
	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testRandomFix() throws Exception {
		double fraction = 0.8;
		fix = new FixingStrategy();
		for (int x=0; x < 10; x++)
		{
			Collection<Variable> vars = fix.getFixedSet(sol,fraction);
			assertTrue(String.format("Size is %d ", vars.size()), vars.size() == 80);

		}
		
	}
	
	@Test
	public void testFixToOne() throws Exception {
		double fraction = 0.8;
		fix = new FixToOneFixingStrategy();
		for (int x=0; x < 10; x++)
		{
			Collection<Variable> vars = fix.getFixedSet(sol,fraction);
			assertTrue(String.format("Size is %d ", vars.size()), vars.size() == 79);
			assertTrue(Collections.min(vars, new Comparator<Variable>() {
				public int compare(Variable a, Variable b)
				{
					return (int)(a.getValue() - b.getValue());
				}
			}).getValue() > 0.0);
		}
		
	}
}
